{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "488b0358",
   "metadata": {},
   "source": [
    "### array数组的数值计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6c29ea59",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "tang_array = np.array([[1,2,3],[4,5,6]])\n",
    "tang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "75e4e89c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(tang_array)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fca3e2f",
   "metadata": {},
   "source": [
    "指定要进行的操作是沿着什么轴（维度）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d95defdc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 7, 9])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(tang_array,axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "98675b92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3ad13c93",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6, 15])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(tang_array,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2609a1e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6, 15])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(tang_array,axis=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e8863a1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 7, 9])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.sum(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a84bc70e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6, 15])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.sum(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4a68bb63",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "720"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.prod()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "202535d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  6, 120])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.prod(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "79c522aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 4, 10, 18])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.prod(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "18e37b06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1c17fe48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 4])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.min(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "ce36c87e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "44f007e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0], dtype=int64)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.argmin(axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "200fb3fc",
   "metadata": {},
   "source": [
    "## 找到索引位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ec28e711",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.argmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "83d88c56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0], dtype=int64)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.argmin(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "065a6f9e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.5, 3.5, 4.5])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.mean(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e6725932",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6134e63",
   "metadata": {},
   "source": [
    "## 标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "af8356f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.707825127659933"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "699957ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.81649658, 0.81649658])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.std(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09baf3e9",
   "metadata": {},
   "source": [
    "## 方差的计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c6503f91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.9166666666666665"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "2e87908d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 2, 3],\n",
       "       [4, 4, 4]])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.clip(2,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "5ad3d90d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 4., 6.])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array = np.array([1.2,3.56,6.4])\n",
    "tang_array.round()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "2d8d89b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.2, 3.6, 6.4])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tang_array.round(decimals=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01792043",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
